/**
 *
 */
import Util;
import OpenApi;

import EndpointUtil;

extends OpenApi;

init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  

  checkConfig(config);
  @endpoint = getEndpoint('databot', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }

  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}
model QueryDatabotRequest {
  accessId?: string(name='AccessId'),
  query?: string(name='Query'),
  sessionId?: string(name='SessionId'),
}

model QueryDatabotResponseBody = {
  costTime?: long(name='CostTime'),
  requestId?: string(name='RequestId'),
  data?: map[string]any(name='Data'),
}

model QueryDatabotResponse = {
  headers: map[string]string(name='headers'),
  body: QueryDatabotResponseBody(name='body'),
}

async function queryDatabotWithOptions(request: QueryDatabotRequest, runtime: Util.RuntimeOptions): QueryDatabotResponse {
  Util.validateModel(request);
  var req = new OpenApi.OpenApiRequest{ 
    body = Util.toMap(request),
  };
  return doRPCRequest('QueryDatabot', '2020-03-30', 'HTTPS', 'POST', 'AK', 'json', req, runtime);
}

async function queryDatabot(request: QueryDatabotRequest): QueryDatabotResponse {
  var runtime = new Util.RuntimeOptions{};
  return queryDatabotWithOptions(request, runtime);
}

